function [ X1, X2, U1, U2, BIU1, BIU2] = UspatialMapPerBlock( h , NIt , NJt , NJe , NIe , UT)
%SPATIALMAP Summary of this function goes here
%   Detailed explanation goes here

x1 = zeros (NIe*NJe,1);
y1 = zeros (NIe*NJe,1);
U1 = zeros (NIe*NJe,size(UT,2));

x2 = zeros ((NIt-NIe)*(NJt-NJe),1);
y2 = zeros ((NIt-NIe)*(NJt-NJe),1);
U2 = zeros ((NIt-NIe)*(NJt-NJe),size(UT,2));

xStart = 0;
yStart = h/2;

index1 = 1;
index2 = 1;

for i = 1:NIt

    if(i<=NIe)
        x1(index1) = xStart + (i-1) * h; 
        y1(index1) = 0;
        U1(index1,:) = zeros(1,size(UT,2)); 
        index1 = index1 + 1;
        x1(index1) = xStart + (i-1) * h; 
        y1(index1) = yStart + (NJe-1/2) * h;
        U1(index1,:) = zeros(1,size(UT,2)); 
        index1 = index1 + 1;
    else
        x2(index2) = xStart + (i-1) * h; 
        y2(index2) = 0;
        U2(index2,:) = zeros(1,size(UT,2)); 
        index2 = index2 + 1;        
        x2(index2) = xStart + (i-1) * h; 
        y2(index2) = yStart + (NJt-1/2) * h;
        U2(index2,:) = zeros(1,size(UT,2)); 
        index2 = index2 + 1;        
    end
    if(i==NIe+1)
        x1(index1) = xStart + (i-1) * h; 
        y1(index1) = 0;
        U1(index1,:) = zeros(1,size(UT,2)); 
        index1 = index1 + 1;            
        x1(index1) = xStart + (i-1) * h; 
        y1(index1) = yStart + (NJe-1/2) * h;
        U1(index1,:) = zeros(1,size(UT,2)); 
        index1 = index1 + 1;            
    end

end

BIU1 = index1; 
BIU2 = index2;

for i=1:NIt
    for j=1:NJt
                
        if (i<=NIe && j>NJe) continue; end
        
        index = Umap (i,j);
        
        if(i<=NIe)
            x1(index1) = xStart + (i-1) * h; 
            y1(index1) = yStart + (j-1) * h;
            U1(index1,:) = UT(index,:); 
            index1 = index1 + 1;
        else
            x2(index2) = xStart + (i-1) * h; 
            y2(index2) = yStart + (j-1) * h;
            U2(index2,:) = UT(index,:); 
            index2 = index2 + 1;
        end
        if(i==NIe+1 && j<=NJe)
            x1(index1) = xStart + (i-1) * h; 
            y1(index1) = yStart + (j-1) * h;
            U1(index1,:) = UT(index,:); 
            index1 = index1 + 1;            
        end
    end
end

X1 = [x1,y1];
X2 = [x2,y2];

end

